From 039c523c56ebaebe8176c46430f2ffda109dd0eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Davidovi=C4=87?= Date: Wed, 24 Dec 2014 03:53:42 +0100 Subject: [PATCH] Handle from_utf8 new return type As per rust-lang/rust@9b99436, the return type of from_utf8 has been changed from Option to Result. Consequently, update code which relied on this return type to work with Ok(...) and Err(...) instead of Some(...) and None --- src/cargo/ops/cargo_rustc/custom_build.rs | 4 ++-- src/cargo/util/errors.rs | 8 ++++---- src/cargo/util/toml.rs | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index 2445a6294..6da051f34 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -7,7 +7,7 @@ use std::sync::Mutex; use core::{Package, Target, PackageId, PackageSet}; use util::{CargoResult, CargoError, human}; -use util::{internal, ChainError, Require}; +use util::{internal, ChainError}; use super::job::Work; use super::{fingerprint, process, Kind, Context, Platform}; @@ -149,7 +149,7 @@ pub fn prepare(pkg: &Package, target: &Target, req: Platform, // This is also the location where we provide feedback into the build // state informing what variables were discovered via our script as // well. - let output = try!(str::from_utf8(output.output.as_slice()).require(|| { + let output = raw_try!(str::from_utf8(output.output.as_slice()).map_err(|_| { human("build script output was not valid utf-8") })); let parsed_output = try!(BuildOutput::parse(output, pkg_name.as_slice())); diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index c33b7f1a7..7dedfa953 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -157,18 +157,18 @@ impl ProcessError { Some(ref out) => { let mut string = String::new(); match str::from_utf8(out.output.as_slice()) { - Some(s) if s.trim().len() > 0 => { + Ok(s) if s.trim().len() > 0 => { string.push_str("\n--- stdout\n"); string.push_str(s); } - Some(..) | None => {} + Ok(..) | Err(..) => {} } match str::from_utf8(out.error.as_slice()) { - Some(s) if s.trim().len() > 0 => { + Ok(s) if s.trim().len() > 0 => { string.push_str("\n--- stderr\n"); string.push_str(s); } - Some(..) | None => {} + Ok(..) | Err(..) => {} } Some(string) }, diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index a74cb1d80..6320270b6 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; + use std::fmt; use std::io::fs::{mod, PathExtensions}; use std::os; @@ -97,7 +98,7 @@ pub fn to_manifest(contents: &[u8], Some(path) => path, None => manifest, }; - let contents = try!(str::from_utf8(contents).require(|| { + let contents = raw_try!(str::from_utf8(contents).map_err(|_| { human(format!("{} is not valid UTF-8", manifest.display())) })); let root = try!(parse(contents, &manifest)); -- 2.30.2